<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="order by dede58.com"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>笔记库后台-角色管理</title>
    <#include "public/link_css.ftl">
    <#include "public/link_js.ftl">
    <#--    <script>window.location.href='upgrade-browser.html';</script>-->
</head>

<body class="user-select">
<section class="container-fluid">
    <#include "public/header.ftl">
    <div class="row">
        <#include "public/left.ftl">
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
            <div class="row">
                <div class="col-md-5">
                    <h1 class="page-header">添加</h1>
                    <form action="/admin/role/add" method="post" autocomplete="off">
                        <div class="form-group">
                            <label for="category-name">角色名称</label>
                            <input type="text" id="category-name" name="role" class="form-control"
                                   placeholder="在此处输入角色名称" required autocomplete="off">
                        </div>
                        <div class="form-group">
                            <label for="category-name">角色描述</label>
                            <input type="text" id="category-name" name="description" class="form-control"
                                   placeholder="在此处输入角色描述" required autocomplete="off">
                        </div>
                        <button class="btn btn-primary" type="submit" name="submit">添加新角色</button>
                    </form>
                </div>
                <div class="col-md-7">
                    <h1 class="page-header">管理 <span class="badge">${roleCount}</span></h1>
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                            <tr>
                                <th><span class="glyphicon glyphicon-paperclip"></span> <span
                                            class="visible-lg">ID</span></th>
                                <th><span class="glyphicon glyphicon-file"></span>
                                    <span class="visible-lg">角色名称</span>
                                </th>
                                <th><span class="glyphicon glyphicon-list-alt"></span> <span
                                            class="visible-lg">角色描述</span></th>
                                <#--                                <th><span class="glyphicon glyphicon-list-alt"></span> <span-->
                                <#--                                            class="visible-lg">所有权限</span></th>-->
                                <th><span class="glyphicon glyphicon-list-alt"></span> <span
                                            class="visible-lg">是否可用</span></th>
                                <th><span class="glyphicon glyphicon-pencil"></span>
                                    <span class="visible-lg">操作</span>
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <#if roleManagerList??>
                                <#list roleManagerList as role>
                                    <tr>
                                        <td>${role.id}</td>
                                        <td>${role.role}</td>
                                        <#if role.description??>
                                            <td>${role.description}</td>
                                        <#else>
                                            <td></td>
                                        </#if>
                                        <td>
                                            <#if role.available==1>
                                                可用
                                            <#else>
                                                不可用
                                            </#if>
                                        </td>
                                        <td><a href="/admin/role/update?id=${role.id}">修改</a>
                                            <a href="/admin/role/delete?id=${role.id}">删除</a>
                                            <a data-toggle="modal"
                                               data-target="#myModal" data-whatever="${role.id}">权限</a>
                                        </td>
                                    </tr>
                                </#list>
                            </#if>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

    </div>
</section>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form method="post" action="/admin/role/addPermission">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">权限列表</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" name="roleId">
                    <#if permissionList??>
                        <#list permissionList as perm>
                            <label class="checkbox-inline">
                                <input name="permissionIds" type="checkbox" value="${perm.id}"> ${perm.name}
                            </label>
                        </#list>
                    </#if>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">添加/修改权限</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('#myModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget) // 获取触发的控件
        var recipient = button.data('whatever') // 获取携带的值
        var modal = $(this)
        modal.find('.modal-body input[type=hidden]').val(recipient) // 为input type=hidden赋值
    })
</script>
</body>
</html>
